home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / sound / driver.zip / TREAD.C < prev    next >
C/C++ Source or Header  |  1987-05-13  |  2KB  |  69 lines

  1. /*    file:    test.c
  2.  
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. /*FILE    *mid;*/
  8. int    mid;
  9. int    val;
  10. int    err;
  11. unsigned char    buf[80];
  12. char    flush[] = "01";        /*0=flush input, 1=flush output*/
  13. char    timer[] = "2xx";    /*2=set timout limit to xx (binary value)*/
  14. unsigned short    timlim;
  15. struct    midistat        /*structure of a midi ioctl return*/
  16. {
  17.     short    prt;
  18.     short    stat;
  19.     short    timeo;
  20.     short    erval;
  21.     short    eroff;
  22.     short    ifirst;
  23.     short    iavail;
  24.     short    ibuf;
  25.     short    ofirst;
  26.     short    oavail;
  27.     short    obuf;
  28. };
  29.  
  30. struct midistat    retstr;
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char    *argv[];
  35. {
  36.     if (argc<2)
  37.     {
  38.         printf("usage: TREAD mididriver\n");
  39.         exit(1);
  40.     }
  41.     mid=mopen(argv[1]);        /*open driver for normal read/write*/
  42.     if (mid==0)
  43.     {
  44.         printf("unable to open device %s\n",argv[1]);
  45.         exit(2);
  46.     }
  47.     printf("Flush buffer? ");    /*ask user yes or no on flush*/
  48.     fgets(buf,79,stdin);
  49.     strupr(buf);
  50.     if (buf[0]=='Y')
  51.         mioctlw(flush,2,mid);        /*flush both buffers*/
  52.     printf("Timeout delay in miliseconds (65534=max, 65535=never): ");
  53.     scanf("%u",&timlim);            /*get time in unsigned int*/
  54.     memcpy(&(timer[1]),&timlim,2);    /*copy into midioctl string*/
  55.     mioctlw(timer,3,mid);
  56.     while(1)
  57.     {
  58.         if ((err=mread(buf,1,mid))==1)    /*read like any other file*/
  59.             printf("%x ",buf[0]);
  60.         else
  61.         {
  62.             mioctlr(&retstr,sizeof(struct midistat),mid);
  63.             printf("\7<%x %x %x> ",err,buf[0],retstr.erval);
  64.             if (retstr.erval&4)            /*if it was overflow,*/
  65.                 mioctlw(flush,2,mid);        /*flush both buffers*/
  66.         }
  67.     }
  68. }
  69.